package org.hgg.workflow.core;

import java.util.concurrent.Callable;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Jarvis
 * @date 2023/12/28 1:53
 */
public class Task<T,R> implements Callable<ExecutionResult<T,R>> {
    private Node<T,R> node;

    public Task(Node<T,R> node) {
        this.node = node;
    }

    @SuppressWarnings("unchecked")
    @Override
    public ExecutionResult<T, R> call() throws Exception {
        System.out.println("task "+node.getName()+" start");
        int mls = ThreadLocalRandom.current().nextInt(5000);
        Thread.sleep(mls);
        System.out.println("task "+node.getName()+" end");

        return new ExecutionResult<>(node, (R)"result", true);
    }
}
